﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using IISHostingApplication;

namespace OOP33rdBatchApplication
{
    public partial class _Default : System.Web.UI.Page
    {
        private DepartmentGateway deparmentGateway = new DepartmentGateway();
        private StudentGateway studentGateway = new StudentGateway();
        List<Student> students = new List<Student>();
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                departmentDropdownlist.DataSource = deparmentGateway.GetAll();
                departmentDropdownlist.DataTextField = "Name";
                departmentDropdownlist.DataValueField = "Id";
                departmentDropdownlist.DataBind();
            }
            
        }

        protected void showButton_Click(object sender, EventArgs e)
        {
            int departmentId = int.Parse(departmentDropdownlist.SelectedValue);
            TextBox1.Text = "";
            students = studentGateway.GetAllStudentsOfDept(departmentId);
            Session["Student"] = students;
            foreach (var student in students)
            {
                TextBox1.Text += student.Name + Environment.NewLine;
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
           
            Response.Redirect("~/StudentPage.aspx");
        }
    }
}